// 接受命令行参数迭代器
use std::env;
use std::process;

use minigrep::Config;
fn main() {
    // let args: Vec<String> = env::args().collect(); //collect()转为集合
                                                   //let query = &args[1];
                                                   //let file_path = &args[2];

    // let (query, file_path) = parse_config(&args);
    // let config = parse_config(&args);
    let config = Config::build(env::args()).unwrap_or_else(|err| {
        eprintln!("Problem parsing arguments: {err}");
        process::exit(1);
    });
    println!("Searching for {}", config.query);
    println!("In file {}", config.file_path);

    if let Err(e) = minigrep::run(config) {
        eprintln!("Application error:{e}");
        process::exit(1);
    }
    //dbg!(args);
}

// fn parse_config(args: &[String]) -> (&str, &str) {
//     let query = &args[1];
//     let file_path = &args[2];
//     (query, file_path)
// }
// fn parse_config(args: &[String]) -> Config {
//     let query = args[1].clone();
//     let file_path = args[2].clone();
//     Config { query, file_path }
// }
